package com.huawei.esdk.tp.business.professional.sitectrl;

import java.util.List;

import org.apache.log4j.Logger;

import com.huawei.esdk.platform.common.SDKErrorCode;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.tp.base.BaseService;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.common.ParamCheck;
import com.huawei.esdk.tp.domain.model.ScheduleConference;

public class SiteCtrlService extends BaseService
{
    private static final Logger LOGGER = Logger
            .getLogger(SiteCtrlService.class);

    public SDKErrorCode connectSites(String confID, List<String> sitesUri)
    {
        SDKErrorCode result = new SDKErrorCode();
        // 校验必填参数
        if (!ParamCheck.checkConfID(confID)
                || !ParamCheck.checkSiteList(sitesUri))
        {
            result.setErrCode(ErrInfo.DATE_TYPE_ERROR);
            return result;
        }
        try
        {
            // 准备Model
            ScheduleConference scheduleConf = new ScheduleConference(confID);
            // 调用Model
            result = scheduleConf.connectSites(sitesUri);
        }
        catch (SDKException ex)
        {
            LOGGER.error("", ex);
            result.setErrCode(ex.getSdkErrCode());
            result.setDescription(null != ex.getSdkErrDesc() ? ex
                    .getSdkErrDesc() : ex.getMessage());
        }
        catch (Exception e)
        {
            LOGGER.error("connectSites method error", e);
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public SDKErrorCode disconnectSites(String confID, List<String> sitesUri)
    {
        SDKErrorCode result = new SDKErrorCode();
        // 校验必填参数
        if (!ParamCheck.checkConfID(confID)
                || !ParamCheck.checkSiteList(sitesUri))
        {
            result.setErrCode(ErrInfo.DATE_TYPE_ERROR);
            return result;
        }
        try
        {
            // 准备Model
            ScheduleConference scheduleConf = new ScheduleConference(confID);
            // 调用Model
            result = scheduleConf.disconnectSites(sitesUri);
        }
        catch (SDKException ex)
        {
            LOGGER.error("", ex);
            result.setErrCode(ex.getSdkErrCode());
            result.setDescription(null != ex.getSdkErrDesc() ? ex
                    .getSdkErrDesc() : ex.getMessage());
        }
        catch (Exception e)
        {
            LOGGER.error("disconnectSites method error", e);
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public SDKErrorCode quietSites(String confID, List<String> sitesUri,
            boolean actionCode)
    {
        SDKErrorCode result = new SDKErrorCode();
        // 校验必填参数
        if (!ParamCheck.checkConfID(confID)
                || !ParamCheck.checkSiteList(sitesUri))
        {
            result.setErrCode(ErrInfo.DATE_TYPE_ERROR);
            return result;
        }
        try
        {
            // 准备Model
            ScheduleConference scheduleConf = new ScheduleConference(confID);
            // 调用Model
            result = scheduleConf.quietSites(sitesUri, actionCode);
        }
        catch (SDKException ex)
        {
            LOGGER.error("", ex);
            result.setErrCode(ex.getSdkErrCode());
            result.setDescription(null != ex.getSdkErrDesc() ? ex
                    .getSdkErrDesc() : ex.getMessage());
        }
        catch (Exception e)
        {
            LOGGER.error("quietSites method error", e);
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

    public SDKErrorCode muteSites(String confID, List<String> sitesUri,
            boolean actionCode)
    {
        SDKErrorCode result = new SDKErrorCode();
        // 校验必填参数
        if (!ParamCheck.checkConfID(confID)
                || !ParamCheck.checkSiteList(sitesUri))
        {
            result.setErrCode(ErrInfo.DATE_TYPE_ERROR);
            return result;
        }
        try
        {
            // 准备Model
            ScheduleConference scheduleConf = new ScheduleConference(confID);
            // 调用Model
            result = scheduleConf.muteSites(sitesUri, actionCode);
        }
        catch (SDKException ex)
        {
            LOGGER.error("", ex);
            result.setErrCode(ex.getSdkErrCode());
            result.setDescription(null != ex.getSdkErrDesc() ? ex
                    .getSdkErrDesc() : ex.getMessage());
        }
        catch (Exception e)
        {
            LOGGER.error("muteSites method error", e);
            result.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
        }
        return result;
    }

}
